#ifndef CSERVOWINDOW_H_
#define CSERVOWINDOW_H_

#include <buola/gui/containers/cmosaiccontainer.h>

#include <buola/scene.h>
#include <buola/scene/csceneview.h>
#include <buola/scene/geodes/cpointcloud.h>
#include <buola/widgets/cimagebox.h>
#include <buola/gui/containers/clistcontainer.h>
#include <buola/widgets/cnumbox.h>
#include <buola/widgets/ccheckbox.h>
#include <buola/cv/cvisualservoing.h>

#include <robot/kuka/cvirtualarm.h>
#include <robot/sdh/cvirtualhand.h>

namespace buola { namespace simulator {

class CServoWindow : public gui::CMosaicContainer
{
    struct SFolder
    {
        io::CURI mURI;
        std::string mFrame;
    };

public:
    CServoWindow(const io::CURI &pFolder);
    virtual ~CServoWindow();

private:
    void SetupScene();
    void SetupJoints(const SFolder &pFolder);
    void SetupViews();
    void SetupInput(const SFolder &pFolder);

    void ResetServo();
    void ShakeServo();
    void BigRun();
    void SaveMask();
    void NextIteration(bool pReally=true,int pCount=1);

    void OnCoordsBox(int i);
    void OnCapture();
    void OnCommitHook(const CRegion &pRegion);
    
    void GeneratePly();
    void GenerateMappableMask();
    
private:
    gui::PToolBar mToolBar;
    
    CTimer mTimer;
    
    img::CImage_rgb8 mTargetImage;
    img::CImage_bgra8 mDirectionsImage;
    img::CImage_rgb8 mInputImage;
    
    cvi::CVisualServoing mVVS;
    std::vector<SFolder> mFolders;
    std::string mFrame;
    
    robot::kuka::CVirtualArm mVirtualArm;
    robot::sdh::CVirtualHand mVirtualHand;
    
    scene::PScene mScene;
        
    scene::PSceneView mSceneView;
    scene::PPointCloud mSceneCloud;
    gui::PImageBox mImageBox[3];
    
    gui::PListContainer mNumbersBox;
    gui::PNumBox mCoordsBox[6];
    gui::PCheckBox m2DBox;
    gui::PCheckBox m3DBox;
};

/*namespace simulator*/ } /*namespace buola*/ }

#endif /* CSERVOWINDOW_H_ */
